Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hasha

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hasha

Hashing made simple. Get the hash of a buffer/string/stream/file.

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is hasha?

The hasha npm package is a Node.js module used for generating hashes from strings, buffers, or streams. It supports various hashing algorithms and can be used for tasks such as checksum generation, file integrity verification, and password hashing.

What are hasha's main functionalities?

String Hashing

Hash a string using a specified algorithm. In this example, the string 'unicorn' is hashed using the MD5 algorithm.

const hasha = require('hasha');

const hash = hasha('unicorn', {algorithm: 'md5'});
console.log(hash); //=> '1abcb33beeb811dca15f0ac3e47b88d9'

Buffer Hashing

Hash a buffer using a specified algorithm. Here, a buffer containing the string 'unicorn' is hashed using the SHA-256 algorithm.

const hasha = require('hasha');

const buffer = Buffer.from('unicorn');
const hash = hasha(buffer, {algorithm: 'sha256'});
console.log(hash); //=> 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'

Stream Hashing

Generate a hash for the content of a stream. In this code sample, the content of 'unicorn.txt' is hashed using the SHA-512 algorithm.

const hasha = require('hasha');
const fs = require('fs');

const stream = fs.createReadStream('unicorn.txt');
hasha.fromStream(stream, {algorithm: 'sha512'}).then(hash => {
  console.log(hash); //=> 'hash of the stream content'
});

File Hashing

Create a hash for the content of a file. This example demonstrates hashing the content of 'unicorn.txt' using the MD5 algorithm.

const hasha = require('hasha');

hasha.fromFile('unicorn.txt', {algorithm: 'md5'}).then(hash => {
  console.log(hash); //=> 'hash of the file content'
});

Hashing with Multiple Algorithms

Hash a value using multiple algorithms at once. The string 'unicorn' is hashed using both MD5 and SHA-1 algorithms, and the result is an array of hashes.

const hasha = require('hasha');

const hashes = hasha('unicorn', {algorithm: ['md5', 'sha1']});
console.log(hashes); //=> ['md5 hash', 'sha1 hash']

Other packages similar to hasha

Keywords

FAQs

Package last updated on 10 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc